<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>模板html</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            background: rgba(90, 194, 255, 1);
        }

        .vueApp {
            padding-bottom: 40px;
        }

        .m-time-mod {
            margin-bottom: 15px;
        }

        .c-time-content {
            font-size: 13px;
            font-weight: 400;
            color: rgba(255, 255, 255, 1);
        }

        .m-order-mod {
            position: relative;
            padding: 20px 15px;
            margin: 15px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 4px 10px 0px rgba(0, 135, 214, 0.37);
            border-radius: 10px;
        }

        .c-order-state {
            font-size: 18px;
            font-weight: bold;
            color: rgba(25, 25, 25, 1);
        }

        .c-order-id {
            font-size: 13px;
            font-weight: 400;
            color: rgba(128, 128, 128, 1);
            margin-top: 12px;
        }

        .m-info-dot {
            position: relative;
        }

        .m-info-dot::after {
            content: "";
            position: absolute;
            right: 10px;
            top: 10px;
            width: 9px;
            height: 9px;
            background: rgba(226, 83, 83, 1);
            border-radius: 50%;
        }

        .long-box {
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            width: 120px;
            height: 42px;
        }

        .top {
            top: -42px;
        }

        .bottom {
            bottom: -49px;
        }

        .bottom img {
            position: absolute;
            top: -7px;
            left: 50%;
            width: 14px;
            height: 7px;
            transform: translateX(-50%) rotate(180deg);
        }

        .top img {
            position: absolute;
            bottom: 0;
            left: 50%;
            width: 14px;
            height: 7px;
            transform: translateX(-50%);
        }

        .long-btn {
            border-radius: 6px;
        }

        .long-btn p {
            position: relative;
            background-color: rgba(35, 35, 35, 0.91);
            color: #fff;
            text-align: center;
            font-size: 12px;
            line-height: 35px;
            height: 35px;
            font-weight: 100;
            width: 60px;
        }

        .long-btn p.right::before {
            content: ' ';
            position: absolute;
            top: 50%;
            left: 0;
            height: 24px;
            background-color: #fff;
            width: 1px;
            transform: scaleX(0.5) translateY(-50%);
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <div v-if="listData.length > 0">
            <div v-for="item,index in listData">
                <div class="m-time-mod" data-flex="main:center cross:center">
                    <div class="c-time-content">
                        {{ item.createDate }}
                    </div>
                </div>
                <div class="m-order-mod" :class="{'m-info-dot': item.ifRead == 0}" @click="orderFn(item, index)" :data-index="index"
                    ontouchstart="gtouchstart(this)" ontouchmove="gtouchmove()" ontouchend="gtouchend()">
                    <div class="c-order-state">{{item.messageTypeName}}</div>
                    <div class="c-order-id">订单号:{{item.orderSn || item.omsOrderReturnApplyOrderSn || item.omsOrderOrderSn}}</div>
                    <div v-if="item.sel" :class="index === 0 ? 'long-box bottom' : 'long-box top'">
                        <div class="long-btn" data-flex="">
                            <p @click.stop="item.ifRead == 0 ? changeIfRead(item,index) : ''">已读</p>
                            <p class="right" @click.stop="deleteMessage(item)">删除</p>
                        </div>
                        <img src="../../image/course/longpress.png" alt="">
                    </div>
                </div>
            </div>
        </div>
        <div v-else-if="isLoad" class="data-null">
            <p>暂时没有订单消息哦</p>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm;
    var pageParam = {};
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        pageParam = api.pageParam;
        fnInit();
    };
    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                listData: [],
                isLoad: false,
                pageNo: 1,
                pageSize: 10
            }
        });
        load();
    }

    function load() {
        getPageData('headerRefreshing');
        fnAddHeaderRefreshingEvent(function() { //设置下拉刷新
            getPageData('headerRefreshing');
        });

        fnAddFooterLoadingEvent(function() { // 设置上拉加载
            getPageData('load');
        });

    }

    function getPageData(sign) {
        if(sign == 'headerRefreshing') {
            vm.pageNo = 1;
        } else {
            vm.pageNo ++;
        }
        var url = 'apiAppMessage/findUserMessageList';
        var params = {
            'messageBigTypeCodes': '02',
            'pageNo': vm.pageNo,
            'pageSize': vm.pageSize
        };
        var callback = function(data) {
            if(vm.pageNo == '1') {
                vm.listData = [];
            }
            
            var listData = data.listData;
            for(var i = 0; i < listData.length; i ++) {
                var item = listData[i];
                item.createDate = formatTime(item.createDate,'order_date');
            }
            api.refreshHeaderLoadDone();
            vm.listData = vm.listData.concat(listData);
            vm.isLoad = true;
            // status 为200时,只返回data
        };
        POST(url, params, callback);
    }

    var timeOutEvent = 0; //定时器
    var longIndex = -1;
    //开始按
    function gtouchstart(el) {
        timeOutEvent = setTimeout(function () {
            var list = vm.listData;
            vm.listData = setPropertyInArray(list, 'sel', false);
            longIndex = el.dataset.index;
            longPress();
        }, 1000); //这里设置定时器，定义长按500毫秒触发长按事件，时间可以自己改，个人感觉500毫秒非常合适
        return false;
    };
    //手释放，如果在500毫秒内就释放，则取消长按事件，此时可以执行onclick应该执行的事件
    function gtouchend() {
        clearTimeout(timeOutEvent); //清除定时器
        if (timeOutEvent != 0) {
            //这里写要执行的内容（尤如onclick事件）
            // alert("你这是点击，不是长按");
        }
        return false;
    };
    //如果手指有移动，则取消所有事件，此时说明用户只是要移动而不是长按
    function gtouchmove() {
        clearTimeout(timeOutEvent); //清除定时器
        timeOutEvent = 0;
    };

    //真正长按后应该执行的内容
    function longPress() {
        timeOutEvent = 0;
        var list = deepCopy(vm.listData);
        list[longIndex].sel = true;
        vm.listData = list;
    }

    function orderFn(item, index) {
        if(item.ifRead != 1) {
            changeIfRead(item,index);
        }

        if(',6,7,8,10,11,'.indexOf(','+item.messageTypeCode+',') !== -1) {
            // 订单消息
            getOrderStatus(item.bussTableId);
        }else if(',9,'.indexOf(','+item.messageTypeCode+',') !== -1) {
            // 视频订单
            fnOpenPublicWin('视频订单', 'teacher/video_order');
        }
    }

    // 获取订单状态
    function getOrderStatus(id) {
        var url = 'common/get';
        var params = {
            "entityName": "omsOrderReturnApply",
            "orderId": id
        };
        var callback = function(data) {
            var status = data.id ? 20 : '';
            id = data.id || id;
            fnOpenPublicWin('订单详情','teacher/order_detail', {
                status: status,
                id: id,
                orderIndex: -1
            });
        };
        POST(url, params, callback);
    }

    // 改变消息状态
    function changeIfRead(item,index) {
        var url = 'apiAppMessage/updateReadStatus';
        var params = {
            'messageInfoId': item.id
        };
        var callback = function (data) {
            vm.listData = setPropertyInArray(vm.listData, 'sel', false);
            var list = deepCopy(vm.listData);
            list[index].ifRead = 1;
            vm.listData = list;
            uploadParent();
        }
        POST(url, params, callback);
    }

    // 删除消息
    function deleteMessage(item) {
        var url = 'apiAppMessage/deleteMessage';
        var params = {
            'messageInfoId': item.id
        };
        var callback = function (data) {
            fnToast('删除成功');
            if(item.ifRead == 0) {
                uploadParent();
            }
            var itemIndex = vm.listData.indexOf(item);
            if(itemIndex !== -1) {
                vm.listData.splice(itemIndex,1);
            }
        }
        POST(url, params, callback);
    }

    // 更新父级消息状态
    function uploadParent() {
        api.execScript({       
            name: pageParam.winName,
            frameName: pageParam.frameName,
            script: 'updateUnreadNum(1);'
        })
    }

    // 点击弹窗外关闭弹窗
    document.body.addEventListener('click', function () {
        vm.listData = setPropertyInArray(vm.listData, 'sel', false);
    })
</script>

</html>